const uRrouter = args => {

    const transArgs = {
        url: '',
        type: 'navigateTo'
    }
    if (Object.prototype.toString.call(args) == '[object String]') {
        transArgs.url = args
    } else if (Object.prototype.toString.call(args) == '[object Object]') {
        if (!args.type) args.type = 'navigateTo'
        Object.assign(transArgs, args)
    }

    const {
        url,
        type
    } = transArgs

    const methodToPatch = ['navigateTo', 'redirectTo', 'switchTab', 'navigateBack']
    if (!methodToPatch.includes(type)) {
        console.log('type必须是以下的值[navigateTo,switchTab,reLaunch,redirectTo]')
        return false
    }

    //根据vuex 判断是否登录
    // if (!store.state.hasLodin) {
    //     uni.showToast('请选登录')
    //     setTimeout(() => {
    //     //执行跳转
    //         startRoute('/pages/login/login', 'redirectTo')
    //     }, 500)
    //     return false
    // }

    startRoute(url, type)

    //开始跳转
    function startRoute(url, type) {
        return new Promise((resolve, reject) =>
            uni[type]({
                url: url,
                success: resolve,
                fail: reject
            })
        )
    }
}

export default uRrouter
